package ooday04;

public class Test {
    public static void main(String[] args) {

        /*Master master=new Master();//
        Dog dog=new Dog("小花狗",3,"花");
        Fish fish =new Fish("金龙鱼",2,"金");
        Chick chick=new Chick("蓝羽鸡",3,"蓝");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);*/





        Animal[] animal=new Animal[5];
        animal[0]=new Dog("小花狗",3,"花");
        animal[1]=new Dog("小奶狗",4,"白");
        animal[2]=new Fish("金龙鱼",2,"金");
        animal[3]=new Fish("大黑鱼",1,"黑");
        animal[4]=new Chick("蓝羽鸡",3,"蓝");
        for (int i = 0; i < animal.length ; i++) {
            System.out.println(animal[i].name);
            animal[i].eat();
            animal[i].drink();//因为数据类型是Animal
                              // 所以无法打点调出子类中的属性和方法
            if(animal[i] instanceof Dog){
                Dog dog =(Dog)animal[i];
                dog.lookAfterHome();
            }

            if(animal[i] instanceof Chick){
                Chick chick =(Chick) animal[i];
                chick.layEggs();
            }
            if(animal[i] instanceof Swim){
                Swim swim =(Swim) animal[i];
                swim.swim();


            }

        }
    }
}
